package com.shuhe.domain.token;


import com.shuhe.common.CommonFunction;
import com.shuhe.common.MyDateUtils;
import com.shuhe.metastore.MetaMysql;
import org.apache.log4j.Logger;

import java.sql.Connection;

public class Token {
    private static Logger logger = Logger.getLogger(Token.class);
    private String userName;
    private String loginName;
    private String expire = MyDateUtils.getNowDate();


    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getLoginName() {
        return loginName;
    }

    public void setLoginName(String loginName) {
        this.loginName = loginName;
    }

    public String getExpire() {
        return expire;
    }

    public void setExpire(String expire) {
        this.expire = expire;
    }

    public void resetExpire() {
        this.expire = MyDateUtils.getNowDate();
    }

    public boolean checkExpire(String key) {
        //true 过期
        try {
            logger.info(this.expire + "---" + MyDateUtils.getNowDate());
            boolean result = MyDateUtils.sfxydqsjq5f(this.expire, -60);
            if (result) {
                String sql = "delete from common_token where token_id = '" + key + "'";
                Connection conn = null;
                try {
                    conn = MetaMysql.connect();
                    MetaMysql.execSql(conn, sql);
                } catch (Exception ex) {
                    ex.printStackTrace();
                } finally {
                    CommonFunction.closeDb(conn);
                }
            }
            return result;
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return false;
    }
}
